using System;
using System.Collections.Generic;

namespace opt.Analysis.Graph
{
	public class GraphNode<T,U>
	{
		private List<GraphArc<T,U>> _arcs;
		private List<GraphArc<T,U>> _back_arcs;
		private U _data;

		public int Count
		{
			get
			{
				return _arcs.Count;
			}
		}

		public U Data
		{
			get
			{
				return _data;
			}
			set
			{
				_data = value;
			}
		}

		public GraphArc<T,U> this[int index]
		{
			get
			{
				if(index >= 0 && index < _arcs.Count)
					return _arcs[index];
				return null;
			}
			set
			{
				if(index >= 0 && index < _arcs.Count)
					_arcs[index] = value;
			}
		}

		public int BackCount
		{
			get
			{
				return _back_arcs.Count;
			}
		}

		public GraphArc<T,U> GetBackGraphArc(int index)
		{
			if(index >= 0 && index < _back_arcs.Count)
				return _back_arcs[index];
			return null;
		}
		
		public void SetBackGraphArc(int index,GraphArc<T,U> arc)
		{
			if(index >= 0 && index < _back_arcs.Count)
				_back_arcs[index] = arc;
		}

		public GraphNode()
		{
			_arcs = new List<GraphArc<T,U>>();
			_back_arcs = new List<GraphArc<T,U>>();
		}

		public GraphNode(U data)
		{
			_arcs = new List<GraphArc<T,U>>();
			_back_arcs = new List<GraphArc<T,U>>();
			_data = data;
		}

		public void RemoveGraphArc(int index)
		{
			if(index >= 0 && index < _arcs.Count)
				_arcs.RemoveAt(index);
		}
		
		public void RemoveBackGraphArc(int index)
		{
			if(index >= 0 && index < _back_arcs.Count)
				_back_arcs.RemoveAt(index);
		}

		public void AddGraphArc(GraphArc<T,U> arc)
		{
			_arcs.Add(arc);
		}
		
		public void AddBackGraphArc(GraphArc<T,U> arc)
		{
			_back_arcs.Add(arc);
		}
	}
}
